package cn.gson.crmdemo.controller.finance;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.gson.crmdemo.model.pojo.PaymentRecord;
import cn.gson.crmdemo.model.service.FkjlService;
import cn.gson.crmdemo.model.vo.FkjlVo;

@Controller
public class FkjlController {
	@Autowired
	FkjlService fs;
	public Map<String,Object> yy(JSONArray selecthk,Page page) {
		Map<String, Object> map=new HashMap<String,Object>();
		map.put("list",selecthk);
		map.put("total",page.getTotal());
		return map;
	}
	@RequestMapping("fkjl")
	@ResponseBody
	public Map<String,Object>hk(Integer pageNum,Integer pasgeSize,Integer jlFk,String jlDate,Integer fpZt){
		System.err.println(jlFk);
		System.err.println(jlDate);
		System.err.println(fpZt);

		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=fs.fkjl(jlFk,jlDate,fpZt);
		//创建Map集合
		return	this.yy(selecthk, page);
	}
	@RequestMapping("fk-fkjl")
	@ResponseBody
	public void fkjl(FkjlVo fo){
		//分页
		fs.addfkjl(fo);
}
	@RequestMapping("addfkjlw")
	public void addfkjl(FkjlVo fo) {
		fs.addfkjl(fo);
	}
	//查询当前时间
	@RequestMapping("sj")
	@ResponseBody
	public String date(FkjlVo fo) {
		java.text.DateFormat format1 = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
       String s = format1.format(new Date());
       	return s;
	}
	//查询随机数
	@RequestMapping("sjs")
	@ResponseBody
	public String sjs() {
       int x=(int)(Math.random()*100000);
       String r="fp";
       String or=r+x;
       	return or;
	}
	//修改状态
	@RequestMapping("updateState")
	public String updateState(int l) {
		fs.updateState(l);
       	return "redirect:fkjl?pageNum=1&pasgeSize=7";
	}
	//模糊查询
	@RequestMapping("fkjl-mhcx")
	@ResponseBody
	public Map<String,Object>selectsj(Integer pageNum,Integer pasgeSize,String rq){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=fs.selectsj("%"+rq+"%");
		//创建Map集合
		return	this.yy(selecthk, page);
	}
	
	//付款方式
	@RequestMapping("fkjl-fkfs")
	@ResponseBody
	public Map<String,Object>selectfs(Integer pageNum,Integer pasgeSize,Integer o){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=fs.selectfs(o);
		//创建Map集合
		return	this.yy(selecthk, page);

}

	
	//是否开票
	@RequestMapping("fkjl-sfkp")
	@ResponseBody
	public Map<String,Object>selectfp(Integer pageNum,Integer pasgeSize,Integer s){
		//分页
		Page<Object> page = PageHelper.startPage(pageNum,pasgeSize);
		//查询数据
		JSONArray selecthk=fs.selectfp(s);
		//创建Map集合
		return	this.yy(selecthk, page);

}
	
	
}
